﻿@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/layuimini/lib/layui-v2.6.3/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuimini/css/public.css" media="all">
    <style>
        body {
            background-color: #ffffff;
        }
    </style>
</head>
<body>
    <div class="layui-form layuimini-form">
        <div class="layui-form-item">
            <label class="layui-form-label required">名称</label>
            <div class="layui-input-block">
                <input type="text" name="name" lay-verify="required" lay-reqtext="客房名称不能为空" placeholder="请输入客房名称" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">客房种类</label>
            <div class="layui-input-block">
                <select name="typeId" id="type1">
                    <option value=""></option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">客房号码</label>
            <div class="layui-input-block">
                <select name="Name" id="type2">
                    <option value=""></option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">身份证</label>
            <div class="layui-input-block">
                <input type="text" name="iD_Card" lay-verify="required" lay-reqtext="不能为空" placeholder="请输入" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">电话</label>
            <div class="layui-input-block">
                <input type="text" name="phone" lay-verify="required" lay-reqtext="不能为空" placeholder="请输入" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label required">性别</label>
            <div class="layui-input-block">
                <input type="radio" name="sex" value="1" title="男" checked="">
                <input type="radio" name="sex" value="0" title="女">
            </div>
        </div>

        <div class="layui-form-item">
            <label class="layui-form-label ">是否已预约</label>
            <div class="layui-input-block">
                <input type="text" name="" placeholder="请输入" value="" class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">入住</button>
            </div>
        </div>
    </div>
        <script src="/layuimini/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
        <script>
            layui.use(['form'], function () {
                var form = layui.form;
                var layer = layui.layer;
                var $ = layui.$;



                //发起异步请求获取房间类别下拉选数据
                $.ajax({
                    url: '/RoomInfo/GetRoomTypeOptions',
                    type: 'get',
                    data: {},
                    success: function (res) {
                        if (res.isSuccess) {
                            //把备选数据放到下拉选标签元素中
                            for (var i = 0; i < res.data.length; i++) {
                                //获取下拉选标签元素,并添加option
                                $("#type1").append('<option value="' + res.data[i].id + '">' + res.data[i].name + '</option>');
                            }

                            //刷新select选择框渲染
                            form.render('select');
                        }
                    }
                });
                //发起异步请求获取房间号码下拉选数据
                $.ajax({
                    url: '/Customer/GetRoomInfoOptions',
                    type: 'get',
                    data: {},
                    success: function (res) {
                        if (res.isSuccess) {
                            //把备选数据放到下拉选标签元素中
                            for (var i = 0; i < res.data.length; i++) {
                                //获取下拉选标签元素,并添加option
                                $("#type2").append('<option value="' + res.data[i].id + '">' + res.data[i].name + '</option>');
                            }

                            //刷新select选择框渲染
                            form.render('select');
                        }
                    }
                });

                //监听提交
                form.on('submit(saveBtn)', function (data) {

                    //添加
                    $.ajax({
                        url: '/Customer/AddCustomer',
                        type: 'post',
                        data: data.field,
                        success: function (res) {
                            if (res.isSuccess) {
                                //重新加载父级表格中的数据
                                //执行搜索重载
                                parent.table.reload('currentTableId', {
                                    page: {
                                        curr: 1
                                    }
                                    , where: {

                                    }
                                }, 'data');

                                //关闭添加的页面
                                var iframeIndex = parent.layer.getFrameIndex(window.name);
                                parent.layer.close(iframeIndex);
                            }
                            parent.layer.msg(res.msg);
                        }
                    });



                    return false;
                });

            });
        </script>
</body>
</html>


